package com.zerdoor.controller;

import com.zerdoor.dao.HomeDao;
import com.zerdoor.model.UserInfo;
import com.zerdoor.service.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Project: acg
 * Module ID: 001
 * Comments: 首页显示
 * JDK version used: JDK1.7
 * Namespace: controller
 * Author：xiaoji
 * Create Date：2014-10-27
 * Modified By：   <修改人中文名或拼音缩写>
 * Modified Date:  <修改日期，格式:YYYY-MM-DD>
 * Why & What is modified  <修改原因描述>
 * Version:                  <版本号>
 */
@Controller
@RequestMapping("/home")
public class HomeController {

    @Autowired
    private HomeService homeService;

    /**
     * FunName:           index
     * Description :      首页
     * @return String：返回首页页面
     * @Author:       xiaoji
     * @Create Date: 2014-10-27
     */
    @RequestMapping("/index")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView();
        //广告
        modelAndView.addObject("ads",homeService.getArtAdvert());
        //进行中的项目展示
        modelAndView.addObject("ongoingPro",homeService.getOngoingBusTaskInfo());
        //题名艺术家
        modelAndView.addObject("artists",homeService.getRecentlyArtist());
        //合作竞赛活动
        modelAndView.addObject("activities",homeService.getCompetitionBusTaskInfo());
        //金牌客户
        modelAndView.addObject("coops",homeService.getCooperation());
        modelAndView.setViewName("/home/index");
        return modelAndView;
    }

    /**
     * FunName:           getFootsInfos
     * Description :      尾部信息异步获取
     * @param request http请求
     * @return Map：返回页面尾部数据
     * @Author:       xiaoji
     * @Create Date: 2014-12-9
     */
    @RequestMapping(value = "getFootsInfos", method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> getFootsInfos(HttpServletRequest request){
        //精选项目分类
        Map<String,Object> map = new HashMap<String, Object>();
        //联系我们
        map.put("aboutus",homeService.getArtAboutus());
        return map ;
    }

    /**
     * FunName:           getProjectClasses
     * Description :      首页精选分类显示
     * @param request http请求
     * @return String：返回登录数据
     * @Author:       xiaoji
     * @Create Date: 2014-10-27
     */
    @RequestMapping(value = "getProjectClasses", method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> getProjectClasses(HttpServletRequest request){
        //精选项目分类
        Map<String,Object> map = new HashMap<String, Object>();
        //map.put("firstLevel",homeService.getFirstBaseTasktype());
        map.put("secondLevel",homeService.getSecondBaseTasktype());
        map.put("thirdLevel",homeService.getThirdBaseTasktype());
        return map ;
    }

    /**
     * FunName:           isAjaxLogin
     * Description :      首页头显示是否登录
     * @param request http请求
     * @return String：返回登录数据
     * @Author:       xiaoji
     * @Create Date: 2014-10-27
     */
    @RequestMapping(value = "isAjaxLogin", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> isAjaxLogin(HttpServletRequest request){
        Map<String,Object> map = new HashMap<String, Object>();
        UserInfo userInfo = (UserInfo)request.getSession().getAttribute("curUser");
        if(userInfo != null ){
            map.put("status", 0);
            map.put("userInfo", userInfo);
        }else{
            map.put("status", -1);
        }
        return map ;
    }
}
